package com.caowei.weicimpress.weicimpress;

import android.os.Parcel;
import android.os.Parcelable;

import java.io.File;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by caoweiPc on 2014/7/18.
 */
public class FileInfoBean implements Parcelable {
    public boolean isCompressed() {
        return isCompressed;
    }

    public void setCompressed(boolean isCompressed) {
        this.isCompressed = isCompressed;
    }

    public FileHandler getCompressFileHandler() {
        return compressFileHandler;
    }

    public void setCompressFileHandler(FileHandler compressFileHandler) {
        this.compressFileHandler = compressFileHandler;
    }

    public long getLastModFileTime() {
        return lastModFileTime;
    }

    public void setLastModFileTime(long lastModFileTime) {
        this.lastModFileTime = lastModFileTime;
    }

    public long getNumOfSubFile() {
        return numOfSubFile;
    }

    public void setNumOfSubFile(long numOfSubFile) {
        this.numOfSubFile = numOfSubFile;
    }

    private long numOfSubFile=0;
    private long lastModFileTime=-1;
    private FileHandler compressFileHandler;
    private boolean inHanding=false;
    private  boolean isCompressed=false;
    /*父文件夹*/
    private File rootFile;
    private String parentPath;
    private String fileName;
    private String date_authrity;
    /*bytes*/
    private BigDecimal size=BigDecimal.valueOf(-1);
    private boolean isDir;
    private int icoId;

    public char[] getPasswd() {
        return passwd;
    }

    public void setPasswd(char[] passwd) {
        this.passwd = passwd;
    }

    private char[] passwd;

    public Map<String, Object> getOtherData() {
        return otherData;
    }

    public void setOtherData(Map<String, Object> otherData) {
        this.otherData = otherData;
    }

    private Map<String,Object> otherData=new HashMap<String, Object>();
    private Callback callback;

    public File getRootFile() {
        return rootFile;
    }

    public void setRootFile(File rootFile) {
        this.rootFile = rootFile;
    }

    public String getParentPath() {
        return parentPath;
    }

    public void setParentPath(String parentPath) {
        this.parentPath = parentPath;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public BigDecimal getSize() {
        return size;
    }

    public void setSize(BigDecimal size) {
        this.size = size;
    }

    public boolean isDir() {
        return isDir;
    }

    public void setDir(boolean isDir) {
        this.isDir = isDir;
    }

    public int getIcoId() {
        return icoId;
    }

    public void setIcoId(int icoId) {
        this.icoId = icoId;
    }

    public Callback getCallback() {
        return callback;
    }

    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    public String getDate_authrity() {
        return date_authrity;
    }

    public void setDate_authrity(String date_authrity) {
        this.date_authrity = date_authrity;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public boolean isInHanding() {
        return inHanding;
    }

    public void setInHanding(boolean inHanding) {
        this.inHanding = inHanding;
    }
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(rootFile);
        dest.writeCharArray(passwd);
        dest.writeValue(isCompressed);
        if(this.compressFileHandler!=null){
            dest.writeString(this.compressFileHandler.getClass().getName());
        }else{
            dest.writeString("null");
        }
        dest.writeLong(numOfSubFile);
        dest.writeLong(lastModFileTime);
        dest.writeString(parentPath);
        dest.writeString(fileName);
        dest.writeString(date_authrity);
        dest.writeValue(size);
        dest.writeValue(isDir);
        dest.writeInt(icoId);
        dest.writeMap(otherData);
        dest.writeValue(callback);
    }
    public static final Parcelable.Creator<FileInfoBean> CREATOR = new Creator(){
        @Override
        public Object createFromParcel(Parcel source) {
            FileInfoBean bean=new FileInfoBean();
            bean.setRootFile((File) source.readValue(null));
            bean.setPasswd(source.createCharArray());
            bean.setCompressed((Boolean) source.readValue(null));
            String fileHandlerClsName= source.readString();
            if(fileHandlerClsName.equals("null")){
                bean.setCompressFileHandler(null);
            }else{
                FileHandler fileHandler= ExecuteFileHandler.getInstance().getHandlerByClsName(fileHandlerClsName);
                bean.setCompressFileHandler(fileHandler);
            }
            bean.setNumOfSubFile(source.readLong());
            bean.setLastModFileTime(source.readLong());
            bean.setParentPath(source.readString());
            bean.setFileName(source.readString());
            bean.setDate_authrity(source.readString());
            bean.setSize((BigDecimal) source.readValue(null));
            bean.setDir((Boolean) source.readValue(null));
            bean.setIcoId(source.readInt());
            bean.setOtherData(source.readHashMap(null));
            bean.setCallback((Callback) source.readValue(null));
            return bean;
        }

        @Override
        public Object[] newArray(int size) {
            return new Object[0];
        }
    };

    public static interface Callback extends Serializable{
        public void callback(Object ...params);
    };
    @Override
    public FileInfoBean clone(){
        FileInfoBean bean=new FileInfoBean();
        bean.setDir(this.isDir);
        bean.setRootFile(this.getRootFile());
        bean.setCompressed(this.isCompressed);
        bean.setCompressFileHandler(this.compressFileHandler);
        bean.setNumOfSubFile(this.getNumOfSubFile());
        bean.setLastModFileTime(this.getLastModFileTime());
        bean.setParentPath(this.getParentPath());
        bean.setFileName(this.getFileName());
        bean.setDate_authrity(this.getDate_authrity());
        bean.setSize(this.getSize());
        bean.setIcoId(this.getIcoId());
        bean.setOtherData(this.getOtherData());
        bean.setCallback(this.getCallback());
        bean.setInHanding(this.inHanding);
        bean.setPasswd(this.passwd);
        return bean;
    }
}
